#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
@todo 福利
@Author : sunp
@Date :2021/11/20
'''
import time


class Welfare:
    def __init__(self, viewClient):
        if not viewClient:
            raise ValueError(f'viewClient is not null,but now it\'s {viewClient}')
        self.vc = viewClient



    '''
    福利宝箱
    '''
    def openBox(self):
        time.sleep(5)
        self.vc.dump()
        view = self.vc.findViewWithText(u'开宝箱得金币')
        if view:
            self.vc.touch(x = 925, y = 1935)
            print(u'发现宝箱，正在打开宝箱...')
            # 点击x关闭宝箱
            self.vc.dump()
            self.vc.touch(x = 540, y = 1650)
        else:
            print(u'宝箱正在等待冷却...')


    '''
    睡觉
    '''
    def openSleep(self):
        self.vc.dump()
        view = self.vc.findViewWithText(u'睡觉赚金币')
        if view:
            print(u'发现睡觉赚金币，点开看看...')
            view.touch()
            time.sleep(5)
            self.vc.dump()
            self.vc.touch(x = 540, y = 2000)
            time.sleep(5)
            self.vc.device.press('KEYCODE_BACK')
        else:
            print(u'还不是睡觉的时候，起来嗨啊！')

    '''
    吃饭
    '''
    def openEat(self):
        view = self.vc.findViewWithText(u'吃饭补贴')
        if view:
            print(u'该吃饭啦，宝贝！干饭人打开看看...')
            view.touch()
            time.sleep(5)
            self.vc.dump()
            # 点击领补贴
            self.vc.touch(x = 540, y = 2010)
            self.vc.dump()
            self.vc.touch(540,1680)
            time.sleep(5)
            self.vc.device.press('KEYCODE_BACK')
        else:
            print(u'还没到吃饭的时候啊！')
